package com.swallow.auth.web.config.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.swallow.auth.infrastructure.mysql.handler.SwallowAuthTenantHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: yangjie.deng@resico.cn
 * @since: 2024-04-09 13:29:58
 * @version: v1.0.0
 * @describe: mybatis-plus 相关配置
 */
@Configuration
@MapperScan(basePackages = {"com.swallow.auth.infrastructure.mysql.mapper"})
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(SwallowAuthTenantHandler tenantHandler) {
        //准备 分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        paginationInnerInterceptor.setMaxLimit(200L);
        //new interceptor
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        //租户拦截器
        interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(tenantHandler));
        interceptor.addInnerInterceptor(paginationInnerInterceptor);

        return interceptor;
    }
}
